package com.allen.webservice.jaxws.service.impl;

import com.allen.webservice.jaxws.config.AuthInterceptor;
import com.allen.webservice.jaxws.domain.Student;
import com.allen.webservice.jaxws.service.StudentService;
import org.apache.cxf.interceptor.InInterceptors;

import javax.jws.WebService;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

//添加拦截器
@InInterceptors(classes = AuthInterceptor.class)
@WebService(name = "studentService", targetNamespace = "http://service.jaxws.webservice.allen.com",
    endpointInterface = "com.allen.webservice.jaxws.service.StudentService")
public class StudentServiceImpl implements StudentService {

    static final List<Student> list = new ArrayList<>();

    static {
        Student student1 = new Student("张三", "男", 11);
        Student student2 = new Student("王红", "女", 12);
        list.add(student1);
        list.add(student2);
    }

    @Override
    public List<Student> getAllStudent() {
        return list;
    }

    @Override
    public Student findStudent(String stuName) {
        final Optional<Student> first = list.stream().filter(student -> student.getName().equals(stuName)).findFirst();
        return first.orElse(null);
    }
}
